package com.shuoyue.ycgk.ui.questionbank.note;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.BaseMvpActivity;
import com.shuoyue.ycgk.base.ListWithPage;
import com.shuoyue.ycgk.entity.QuestionNote;
import com.shuoyue.ycgk.ui.common.NoteContract;
import com.shuoyue.ycgk.utils.XToast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class EditNoteActivity extends BaseMvpActivity<NoteContract.Presenter> implements NoteContract.View, MyNoteContract.View {


    @BindView(R.id.back)
    ImageButton back;
    @BindView(R.id.page_title)
    TextView pageTitle;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.note_edit)
    EditText noteEdit;

    int questionId;
    public static int REQUEST_CODE = 10924;
    MyNoteContract.Presenter presenter;

    public static void start(Context sourse, int questionId) {
        sourse.startActivity(new Intent(sourse, EditNoteActivity.class).putExtra("id", questionId));
    }


    public static void startForResult(Activity sourse, int questionId) {
        sourse.startActivityForResult(new Intent(sourse, EditNoteActivity.class).putExtra("id", questionId), REQUEST_CODE);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_edit_note;
    }

    @Override
    protected void initView() {
        pageTitle.setText("写笔记");
        tvRight.setVisibility(View.VISIBLE);
        tvRight.setText("提交");
    }

    @Override
    public void initData() {
        questionId = getIntent().getIntExtra("id", -1);
        mPresenter = new NoteContract.Presenter();
        mPresenter.attachView(this);
        presenter = new MyNoteContract.Presenter();
        presenter.attachView(this);
        presenter.getMyNote(questionId);
    }

    @OnClick({R.id.back, R.id.tv_right})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                finish();
                break;
            case R.id.tv_right:
                if (noteEdit.getText().toString().length() > 0) {
                    mPresenter.saveNote(questionId, noteEdit.getText().toString());
                } else {
                    XToast.toast(mContext, "请填写笔记");
                }
                break;
        }
    }

    @Override
    public void setNotes(ListWithPage<QuestionNote> list) {

    }

    @Override
    public void addNoteSuc() {
        setResult(RESULT_OK);
        finish();
    }

    @Override
    public void praiseResult(QuestionNote actionId, boolean isPraised) {

    }

    @Override
    public void setNote(QuestionNote note) {
        if (note != null) {

        }
    }
}
